package com.demo.chapter3lambda;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class LambdaDemo {

	private static String processFile(IBufferedReaderProcessor p) throws FileNotFoundException, IOException{
		try(BufferedReader br = new BufferedReader(new FileReader("data.txt"))){
			return p.process(br);
		}
	}

	public static void main(String[] args) throws FileNotFoundException, IOException {
		//lambda表达式的签名和方法签名一致，所以可以传入该表达式
		System.out.println(LambdaDemo.processFile(br -> br.readLine()));
		System.out.println(LambdaDemo.processFile(br -> br.readLine() + br.readLine()));

		//如果一个lambda的主体是一个语句表达式，它就和一个返回void的函数描述符兼容（当然需要参数列表也兼容）
		List list = new ArrayList();
		Predicate<String> p = s -> list.add(s);
		Consumer<String> b = s -> list.add(s);
	}

}
